package com.koron.common.core.business.workflow.bean.param;

import com.koron.common.core.business.workflow.util.SecretUtil;
import lombok.Data;
import lombok.ToString;

/**
 * 工作流模板基本参数
 * @author jzp
 * @since 2021/3/26 16:07
 */
@Data
@ToString
public class BaseParam {
    private String appCode;
    private String setCode;
    private String processCode;
    private String secret;

    public BaseParam() {
    }

    public BaseParam(String appCode, String setCode, String processCode) {
        this.appCode = appCode;
        this.setCode = setCode;
        this.processCode = processCode;
        getSecret();
    }

    public String getSecret() {
        if (secret == null) {
            secret = SecretUtil.getSecret(getAppCode());
        }
        assert !secret.equals("") : "secret不能为空字符串";  // 断言secret不为空字符串
        return secret;
    }

    // 外部不允许设置secret
    private void setSecret(String secret) {
        this.secret = secret;
    }

    public BaseParam clearProcessCode() {
        setProcessCode(null);
        return this;
    }
}
